<?php if (defined("YTDJ") or die()); 

class YouTubeFeedList extends FeedHelper {
	
	var $entries = array();
	
	function __construct($q, $startindex, $maxresults) {
		$url = "http://gdata.youtube.com/feeds/api/videos?vq=".urlencode($q)."&orderby=relevance&start-index=$startindex&max-results=$maxresults&format=5";
		$xml = $this->loadFeed($url);
		
		for ($i = 1; $i <= count($xml->entry); $i++) {
			$entry = self::getAllXPathForEntry($xml, $i);
			// convert url to id
			$entry["id"] = FeedHelper::getIdFromUrl($entry["url"]);
			unset($entry["url"]);
			$this->entries[$entry["id"]] = $entry;
		}
		
		return $this->entries;
		
	}
	
	function getAllXPathForEntry(SimpleXMLElement &$xml, $i) {
		$ret = array();
		foreach (Config::getInstance()->entry_xpath as $key => $xpath) {
			$ret[$key] = self::getXPath($xml, "/default:feed/default:entry[$i]/".$xpath);
		}
		return $ret;
	}
	
}

?>